//此文件为Transducer——M IMU陀螺仪驱动，由电控组王川负责  电话 17609531594

#ifndef _TRANSDUCERM_H
#define _TRANSDUCERM_H
#include "device.h"

#define TRANSDUCER_HEAD_1   0xAA//数据包头1
#define TRANSDUCER_HEAD_2   0x55//数据包头2
//挂载信息
#define EP_CMD_BITS_    (7)
#define EP_RES_BITS_    (3)
#define EP_ID_BITS_     (11)
typedef struct
{
    uint32_t cmd        : EP_CMD_BITS_;
    uint32_t res        : EP_RES_BITS_;
    uint32_t fromId     : EP_ID_BITS_;
    uint32_t toId       : EP_ID_BITS_;
}_Payload_Information;

//状态机
typedef enum 								                       		
{
    IMU_PACK_STATE_HEADER   = 0x00,     //数据包头
    IMU_PACK_STATE_LENTH    = 0x01,     //数据类型
    IMU_PACK_STATE_DATA     = 0x02,     //接收数据
    IMU_PACK_STATE_CHECK    = 0x03      //校验位
} IMU_PACK_STATE;

//陀螺仪数据状态
typedef struct
{
    IMU_PACK_STATE packstate;
    uint8_t length;
    uint8_t data[100];
    int16_t sum;
} IMU_STATE, *P_IMUSTATE;


typedef struct
{
    uint32_t timeStamp; // 时间戳 (uS)
    float q[4]; // 四元数数据
} Ep_Q_s1_e;//四元数数据

typedef struct
{
    uint32_t timeStamp; // 时间戳 (uS)
    float roll; // 翻滚角 (degree)
    float pitch; // 俯仰角 (degree)
    float yaw; // 偏航角 (degree)
    float first_yaw;
    int16_t         circle_yaw;
    uint8_t         first_flag;
} Ep_RPY;//角度数据

typedef struct
{
    uint32_t timeStamp; // 时间戳(uS)
    float gyro[3]; // 陀螺仪数据 Rate (rad/s)
    float acc[3]; // 加速度 (g)
    float mag[3]; // 磁力计数据
} Ep_Raw_GyroAccMag;


typedef struct
{
    Ep_Raw_GyroAccMag basedata;     //陀螺仪基本数据 
    Ep_RPY angle;   //角速度
    Ep_Q_s1_e quaternion;       //四元数
} IMU_DATA, *P_IMU_DATA;

typedef struct
{
    IMU_DATA   data;
    IMU_STATE  state;
} IMU_HANDLE, *P_IMU_HANDLE;

extern float a_z;
extern uint8_t mpu_flag;
extern int16_t circle_yaw;
extern uint8_t first_flag;

void Init_IMU(P_IMU_HANDLE pimu_hadl);
void TransducerM_Rev(P_IMU_HANDLE imu,uint8_t data);
void TransducerM_UART_DMA_Rev(P_IMU_DATA pimu_data, uint8_t data[]);
#endif
